﻿#pragma once

#include <csignal>
#include <cstddef>
#include <functional>
#include <cstdint>

#include "Common.hpp"
#include "Singleton.hpp"

ETERFREE_SPACE_BEGIN

class SignalManager final
{
public:
	enum class Strategy : std::uint8_t
	{
		DEFAULT, OVERLAP
	};

public:
	using Handler = decltype(SIG_ERR);

	using IDType = std::size_t;
	using Observer = std::function<void(int)>;

private:
	friend SignalManager& Singleton<SignalManager>::get();

private:
	static void handle(int _signal);

public:
	static Handler getHandler(int _signal);

	static void setHandler(int _signal, Handler _handler);

	static Strategy getStrategy(int _signal);

	static void setStrategy(int _signal, Strategy _strategy);

private:
	SignalManager() noexcept = default;

public:
	bool insertObserver(int _signal, \
		IDType _id, const Observer& _observer);
	bool insertObserver(int _signal, \
		IDType _id, Observer&& _observer);

	bool removeObserver(int _signal, IDType _id);
};

ETERFREE_SPACE_END
